perm filename EFTPW.C[11,HE] blob
sn#688193 filedate 1982-12-06 generic text, type T, neo UTF8
/* LINTLIBRARY */
/*
* eftpwrite.c
*
* EFTP Package
*
* EftpWrite -- write an arbitrary buffer on an eftp channel
*
* Jeffrey Mogul @ Stanford 28-January-1981
*/
#include <eftp.h>
#include <puplib.h>
#include <pupstatus.h>
#define min(a,b) ( (a<b)? a:b )
EftpWrite(EfChan,buffer,buflen)
struct EftpChan *EfChan; /* eftp channel to write on */
char *buffer; /* buffer to write */
int buflen; /* length of buffer */
{ /* */
char swapbuf[EFTP_MAX_PACKET]; /* for byte-swapping */
int ThisChunk; /* size of current packet */
char *bptr; /* buffer pointer */
int status; /* status from EfSendPckt */
bptr = buffer;
while (buflen > 0) { /* send next buffer */
ThisChunk = min(EFTP_MAX_PACKET, buflen);
/* decide how much to send this time */
#ifdef PUP__NNSO /* nonstandard machine (eg, VAX) */
if (EfChan->ef_mode&EFTPM_BYTESWAP) /* no physical swap */
status = EfSendPckt(EfChan,bptr,ThisChunk);
else { /* swap bytes to stay in standard order */
swab(bptr,swapbuf,ThisChunk);
status = EfSendPckt(EfChan, swapbuf, ThisChunk);
}
#else /* standard machine (e.g., MC68000) */
if (EfChan->ef_mode&EFTPM_BYTESWAP) { /* physical swap */
swab(bptr,swapbuf,ThisChunk);
status = EfSendPckt(EfChan, swapbuf, ThisChunk);
}
else /* bytes already in standard order */
status = EfSendPckt(EfChan,bptr,ThisChunk);
#endif
/* "status" now holds returned status from EfSendPckt */
switch ((int)status) {
case OK: /* it worked - move on to next chunk */
bptr += ThisChunk;
buflen -= ThisChunk;
break;
case TIMEOUT: /* timed out */
return(TIMEOUT);
case EFTP_BADACK: /* got future ack, must restart */
EftpErrMsg[0] = 0; /* no message */
return(EFTP_RESTART);
case EFTP_ABORT: /* depends what sort of abort */
switch((int)EftpAbortCode) {
case EFTPA_EXTSENDER: /* External Sender Abort */
case EFTPA_EXTRECEIVER: /* External Receiver Abort */
return(EFTP_ABORT);
case EFTPA_RECBUSY: /* Receiver Busy Abort */
return(EFTP_WAIT);
case EFTPA_OUTOFSYNCH: /* Out Of Synch Abort */
return(EFTP_RESTART);
case EFTPA_LONGWAIT: /* Long Wait Abort */
case EFTPA_MEDWAIT: /* Medium Wait Abort */
return(EFTP_WAIT);
case EFTPA_SUSPREQ: /* Suspend Request Abort */
sleep(5); /* depends upon EfSendPckt */
break; /* having not bumped sequence */
case EFTPA_MISC: /* Misc Abort */
default: /* dunno */
return(EFTP_ABORT);
} /* end switch on EftpAbortCode */
case EFTP_ERROR: /* got SOMETHING nasty, abort */
return(EFTP_ERROR);
} /*end switch on return from EfSendPckt */
} /* end while loop */
/* it worked */
return(OK);
}